/*
 * weibopay.com Inc.
 * Copyright (c) 2012 All Rights Reserved.
 */
package sc.test.spring.ibatis.ibatis;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import sc.test.spring.ibatis.daointerface.SchedDAO;

// auto generated imports
import sc.test.spring.ibatis.dataobject.SchedDO;
import org.springframework.dao.DataAccessException;
import java.util.Date;
//import com.weihui.biz.common.util.PageList;
import java.util.Map;
import java.util.HashMap;
//import com.weihui.common.lang.Paginator;

/**
 * An ibatis based implementation of dao interface <tt>sc.test.spring.ibatis.daointerface.SchedDAO</tt>.
 *
 * This file is generated by <tt>counter-dalgen</tt>, a DAL (Data Access Layer)
 * code generation utility specially developed for <tt>iwallet</tt> project.
 * 
 * PLEASE DO NOT MODIFY THIS FILE MANUALLY, or else your modification may
 * be OVERWRITTEN by someone else. To modify the file, you should go to 
 * directory <tt>(project-home)/biz/dal/src/conf/dalgen</tt>, and 
 * find the corresponding configuration file (<tt>tables/t_sched.xml</tt>). 
 * Modify the configuration file according to your needs, then run <tt>iwallet-dalgen</tt> 
 * to generate this file.
 *
 * @author Eric.fu
 */
public class IbatisSchedDAO extends SqlMapClientDaoSupport implements SchedDAO {
	/**
	 *  Insert one <tt>SchedDO</tt> object to DB table <tt>T_SCHED</tt>, return primary key
	 *
	 *  <p>
	 *  The sql statement for this operation is <br>
	 *  <tt>insert into t_sched(sched_id,sched_name,gmt_create) values (?, ?, sysdate)</tt>
	 *
	 *	@param sched
	 *	@return long
	 *	@throws DataAccessException
	 */	 
    public long insert(SchedDO sched) throws DataAccessException {
    	if (sched == null) {
    		throw new IllegalArgumentException("Can't insert a null data object into db.");
    	}
    	
        getSqlMapClientTemplate().insert("MS-SCHED-INSERT", sched);

        return sched.getSchedId();
    }

	/**
	 *  Insert one <tt>SchedDO</tt> object to DB table <tt>T_SCHED</tt>, return primary key
	 *
	 *  <p>
	 *  The sql statement for this operation is <br>
	 *  <tt>insert into t_sched(sched_id,sched_name,gmt_create) values (seq_sched.nextval, ?, sysdate)</tt>
	 *
	 *	@param sched
	 *	@return long
	 *	@throws DataAccessException
	 */	 
    public long insert2(SchedDO sched) throws DataAccessException {
    	if (sched == null) {
    		throw new IllegalArgumentException("Can't insert a null data object into db.");
    	}
    	
        getSqlMapClientTemplate().insert("MS-SCHED-INSERT-2", sched);

        return sched.getSchedId();
    }

	/**
	 *  Update DB table <tt>T_SCHED</tt>.
	 *
	 *  <p>
	 *  The sql statement for this operation is <br>
	 *  <tt>update t_sched set sched_name=? where (sched_id = ?)</tt>
	 *
	 *	@param sched
	 *	@return int
	 *	@throws DataAccessException
	 */	 
    public int update(SchedDO sched) throws DataAccessException {
    	if (sched == null) {
    		throw new IllegalArgumentException("Can't update by a null data object.");
    	}


        return getSqlMapClientTemplate().update("MS-SCHED-UPDATE", sched);
    }

	/**
	 *  Update DB table <tt>T_SCHED</tt>.
	 *
	 *  <p>
	 *  The sql statement for this operation is <br>
	 *  <tt>update t_sched set sched_name=? where ((sched_id = ?) AND (gmt_create >= ?) AND (gmt_create < ?))</tt>
	 *
	 *	@param schedName
	 *	@param schedId
	 *	@param gmtCreate
	 *	@param gmtCreate2
	 *	@return int
	 *	@throws DataAccessException
	 */	 
    public int updateByCondition(String schedName, long schedId, Date gmtCreate, Date gmtCreate2) throws DataAccessException {
        Map param = new HashMap();

        param.put("schedName", schedName);
        param.put("schedId", new Long(schedId));
        param.put("gmtCreate", gmtCreate);
        param.put("gmtCreate2", gmtCreate2);

        return getSqlMapClientTemplate().update("MS-SCHED-UPDATE-BY-CONDITION", param);
    }

	/**
	 *  Query DB table <tt>T_SCHED</tt> for records.
	 *
	 *  <p>
	 *  The sql statement for this operation is <br>
	 *  <tt>select sched_id, sched_name, gmt_create from t_sched</tt>
	 *
	 *	@param pageSize
	 *	@param pageNum
	 *	@return PageList
	 *	@throws DataAccessException
	 */	 
//    public PageList selectByCondition(int pageSize, int pageNum) throws DataAccessException {
//        Map param = new HashMap();
//
//        param.put("pageSize", new Integer(pageSize));
//        param.put("pageNum", new Integer(pageNum));
//
//        Paginator paginator = new Paginator();
//        paginator.setItemsPerPage(pageSize);
//        paginator.setPage(pageNum);
//
//        paginator.setItems(((Integer) getSqlMapClientTemplate().queryForObject("MS-SCHED-SELECT-BY-CONDITION-COUNT-FOR-PAGING", param)).intValue());
//        
//        PageList  pageList = new PageList();
//        pageList.setPaginator(paginator);
//        
//        if (paginator.getBeginIndex() <= paginator.getItems()) {
//            param.put("startRow", new Integer(paginator.getBeginIndex()));
//            param.put("endRow", new Integer(paginator.getEndIndex()));
//            pageList.addAll(getSqlMapClientTemplate().queryForList("MS-SCHED-SELECT-BY-CONDITION", param));
//        }
//        
//        return pageList;
//    }

}